﻿namespace NTLib.Core.UTest.Configuration
{
    using Core.Configuration;
    using Core.Configuration.Values;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Test.Resources;

    [TestClass]
    public class ConfigurationCollectionUTest : BaseTestClass
    {
        #region Methods

        /// <summary>
        /// Check if the method used to add directly ConfigValue use correctly the ConfigKey 
        /// as key and merge in the collection if the element already exists.
        /// </summary>
        [TestCategory("Configuration")]
        [TestMethod]
        public void Config_Collection_add()
        {
            string keyOne = "keyOne";
            string valueOne = "ValueOne";
            string valueTwo = "ValueTwo";

            ConfigurationCollection collection = new ConfigurationCollection();

            StringConfig config = new StringConfig(keyOne, valueOne);
            StringConfig config2 = new StringConfig(keyOne, valueTwo);

            collection.Add(config);

            Assert.AreEqual(collection.Count, 1);
            Assert.AreEqual(collection.First().Key, config.ConfigKey);

            collection.Add(config2);

            Assert.AreEqual(collection.Count, 1);
            Assert.AreEqual(collection.First().Key, config.ConfigKey);
            Assert.AreEqual(collection.First().Value.Count, 2);
        }

        /// <summary>
        /// Check if the method used to addRange directly ConfigValue use correctly the ConfigKey 
        /// as key and merge in the collection if the element already exists.
        /// </summary>
        [TestCategory("Configuration")]
        [TestMethod]
        public void Config_Collection_addRange()
        {
            string keyOne = "keyOne";
            string keyTwo = "keyTwo";
            string valueOne = "ValueOne";
            string valueTwo = "ValueTwo";

            ConfigurationCollection collection = new ConfigurationCollection();

            StringConfig config = new StringConfig(keyOne, valueOne);
            StringConfig config2 = new StringConfig(keyOne, valueTwo);
            StringConfig config3 = new StringConfig(keyTwo, valueTwo);

            var collConfigs = new List<ConfigValue>() { config, config3, config2 };

            collection.AddRange(collConfigs);

            Assert.AreEqual(collection.Count, 2);
            Assert.AreEqual(collection.First().Key, config.ConfigKey);
            Assert.AreEqual(collection.First().Value.Count, 2);
            Assert.AreEqual(collection.Last().Key, config3.ConfigKey);
        }


        #endregion
    }
}
